﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _17_事件_练习
{

    class Perosn
    {
        public event Action Fire = null;

        public void Shoot()
        {
            Console.WriteLine("人开枪了");
            Fire?.Invoke();
        }
    }

    class Bird
    {
        public int ID { get; set; }

        public Bird(int iD)
        {
            ID = iD;
        }

        public void Fly()
        {
            Console.WriteLine("鸟-{0}飞走了", ID);
        }


    }

    internal class Program
    {
        static void Main(string[] args)
        {
            Perosn pr = new Perosn();

            //Bird bird1 = new Bird(1);
            //Bird bird2 = new Bird(2);
            //Bird bird3 = new Bird(3);

            //pr.Fire += bird1.Fly;
            //pr.Fire += bird2.Fly;
            //pr.Fire += bird3.Fly;

            //pr.Shoot();//人开枪了


            for (int i = 1; i <= 3; i++)
            {
                int index = i;
                pr.Fire += () => Console.WriteLine("鸟-{0} 飞走了", index);
            }

            pr.Shoot();


            Console.Read();
        }
    }
}
